﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MediaGarden.Playlists.Services;
using Downplay.Origami.Services;
using Orchard.DisplayManagement;
using Orchard.Mvc;

namespace MediaGarden.Playlists.Formats
{
    public class ShapePlaylistWriter : IPlaylistWriter
    {
        private readonly IOrigamiService _origamiService;
        dynamic Shape { get; set; }

        public ShapePlaylistWriter(
                        IOrigamiService origamiService,
                            IShapeFactory shapeFactory

            ) {
                _origamiService = origamiService;
            Shape = shapeFactory;
        }

        public string WriterName
        {
            get { return "Shape"; }
        }

        public System.Web.Mvc.ActionResult WriteMvcResult(System.Web.Mvc.ControllerBase controller, PlaylistContext context)
        {
            // TODO: Needs some work; must have appropriate alternates names for the Playlist shape to allow templates for different types
            // Also need to ensure this returns partial view not an entire template ...
            var shape = Shape.Playlist();
            _origamiService.BuildDisplayShape(context.Playlist, shape, "Playlist", "Playlist");
            return new ShapeResult(controller, shape);
        }
    }
}